<template>
  <div>
    <el-table v-loading="loading" :data="infoList" border header-cell-class-name="bg-F4F8FF">
      <el-table-column label="要求清洗日期" align="center" prop="cleanTime"/>
      <el-table-column label="提醒类型" align="center" prop="cleanStatus" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="550px">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleInfo(scope.row)"
          >处置</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog title="上传布草清洗记录" :visible.sync="visible" width="500px">
      <el-form :model="addForm" ref="addForm" label-width="100px" :rules="addRules">
        <el-form-item label="清洗数量" prop="cleanCount">
          <el-input v-model="addForm.cleanCount" placeholder="请输入清洗数量"></el-input>
        </el-form-item>
        <el-form-item label="清洗类型" prop="type">
          <el-select v-model="addForm.type" clearable style="width: 100%;">
            <el-option v-for="item in dict.type.clean_type" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="图片" prop="picUrl">
          <image-upload v-model="addForm.picUrl"></image-upload>
        </el-form-item>
        <el-form-item >
          <el-button @click="visible = !visible">返回</el-button>
          <el-button type="primary" @click="save">提交</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { getCleanUnCleanList,addClean } from '@/api/zhangping/publicPlace'
export default {
  name: 'pxtxTable',
  dicts: ['clean_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 一企一档表格数据
      infoList: [
      ],
      // 查询参数
      queryParams: {
        pageNum:1,
        pageSize:10,
      },
      visible:false,
      addForm:{
        cleanCount:'',
        type:'',
        picUrl:'',
      },
      addRules:{
        cleanCount:[{
          required: true, message: "清洗数量不能为空", trigger: "blur"
        }],
        type:[{
          required: true, message: "清洗类型不能为空", trigger: "blur"
        }],
        picUrl:[{
          required: true, message: "图片不能为空", trigger: "change"
        }]
      },
    };
  },
  created() {
    this.loading = false
    this.getList();
  },

  methods :{
    save(){
      this.$refs.addForm.validate(valid => {
        if(valid){
          if(this.addForm.id){
            editClean({
              ...this.addForm,
            }).then(res=>{
              if(res.code==200){
                this.$message.success('编辑成功')
                this.getList()
                this.visible = false
              }
            })
          }else{
            addClean({
              ...this.addForm,
              creditCode:'229397350881813143'
            }).then(res=>{
              if(res.code==200){
                this.$message.success('添加成功')
                this.getList()
                this.visible = false
              }
            })
          }

        }
      })
    },
    getList(){
      getCleanUnCleanList({
        ...this.queryParams,
        creditCode:'229397350881813143'
      }).then(res=>{
        this.total = res.total
        this.infoList = res.rows
      })
    },
    handleInfo(row) {
      this.visible = true
    },
  }

}
</script>

<style>

</style>
